﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WpfTwitterClient.Infrastructure
{
    public static class StringExtensions
    {
        public static DateTime ParseDateTime(this  string date)
        {

            string dayOfWeek = date.Substring(0, 3).Trim();

            string month = date.Substring(4, 3).Trim();

            string dayInMonth = date.Substring(8, 2).Trim();

            string time = date.Substring(11, 9).Trim();

            string offset = date.Substring(20, 5).Trim();

            string year = date.Substring(25, 5).Trim();

            string dateTime = string.Format("{0}-{1}-{2} {3}", dayInMonth, month, year, time);

            DateTime ret = DateTime.Parse(dateTime);

            return ret;

        }

        public static List<string> SplitWithStringSeparator(this string line, string separator)
        {
            return line.Split(new string[] { separator }, StringSplitOptions.None).ToList();
        }

        public static string ChopLeft(this string line, string removeThis)
        {
            int removeThisLength = removeThis.Length;
            if (line.Length >= removeThisLength)
            {
                if (line.StartsWith(removeThis))
                    return line.Substring(removeThisLength, line.Length - removeThisLength);
                else
                    return line;
            }
            else
                return line;
        }
    
    }
}
